// src/plugins/axios.js
import axios from 'axios' // 移除未使用的 createApp 导入

const service = axios.create({
  baseURL: '/api',
  timeout: 5000
});

// 请求拦截器
service.interceptors.request.use(
  config => config,
  error => Promise.reject(error)
);

// 响应拦截器
service.interceptors.response.use(
  response => response,
  error => Promise.reject(error)
);

// Vue3插件写法
export default {
  install: (app) => {
    app.config.globalProperties.$axios = service;
    app.provide('$axios', service);
    if (typeof window !== 'undefined') {
      window.axios = service;
    }
  }
};